//
//  CZPresentationController.swift
//  GZWeibo007
//
//  Created by newuser on 16/1/1.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

///model的控制器关闭通知
let SCPresentationControllerDismissNotificaiton = "SCPresentationControllerDismissNotificaiton"

class CZPresentationController: UIPresentationController {

    
    ///容器视图布局
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        containerView?.addSubview(bkgView)
        
        bkgView.ff_Fill(containerView!)
        
        //将背景推到最底部
        containerView?.sendSubviewToBack(bkgView)
        
        //获取modal出来的控制器
        let modelView = presentedView()
        
        //修改大小
        modelView?.frame = CGRect(x: 100, y: 56, width: 200, height: 300)
        
    }
    
    
    
    //背景被点击的方法
    func bkgViewClick() {
        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
             NSNotificationCenter.defaultCenter().postNotificationName(SCPresentationControllerDismissNotificaiton, object: self)
    }
    
    
    //MARK: - 懒加载
    private lazy var bkgView: UIView = {
    
        let view = UIView()
        
        view.backgroundColor = UIColor(white: 0.3, alpha: 0.2)
        
        //点背景击手势
        let tap = UITapGestureRecognizer(target: self, action: "bkgViewClick")
        view.addGestureRecognizer(tap)
        return view
    }()
}
